package com.zlzxm.shoesmarket.viewmodel;

import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.MutableLiveData;

import com.zlzxm.shoesmarket.globle.UserManager;
import com.zlzxm.shoesmarket.net.BaseCallBack;
import com.zlzxm.shoesmarket.net.repository.WareRepository;
import com.zlzxm.shoesmarket.net.respone.BaseResponse;
import com.zlzxm.shoesmarket.net.request.RqWareAdd;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.window.wheelpick.EntityOption;
import com.zlzxm.shoesmarket.viewmodel.entity.EntityRepositoryType;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;

/**
 * Created by zlz
 * on  4/14/21
 */
public class VMAddRepository extends BaseViewModel {

    WareRepository wareRepository = new WareRepository();

    public MutableLiveData<String> liveToast = new MutableLiveData<>();

    public MutableLiveData<EntityOption> liveSelectType = new MutableLiveData();

    public void addRepository(DialogFragment dialogFragment , FragmentManager fragmentManager
    ,String charge,String name){

        RqWareAdd rqWareAdd = new RqWareAdd(charge,name,liveSelectType.getValue().getId(), UserManager.getInstance().getId());

        wareRepository.add(rqWareAdd)
                .compose(RxAndroidHelp.turn(dialogFragment,fragmentManager))
                .subscribe(new BaseCallBack<String>() {
                    @Override
                    protected void succeed(String msg, String s) {

                        liveSucceedToast.setValue(msg);
                    }

                    @Override
                    protected void failed(String msg) {
                        liveErrorToast.setValue(msg);
                    }

                    @Override
                    protected void notLogin() {

                    }
                },throwableCallback);


    }


    //<editor-fold defaultState="collapsed" desc="测试数据">



    // </editor-fold>


}
